//
//  PWSCalendarDayCell.m
//  PWSCalendar
//
//  Created by Sylar on 3/14/14.
//  Copyright (c) 2014 PWS. All rights reserved.
//
////////////////////////////////////////////////////////////////////////
#import "PWSCalendarDayCell.h"
#import "PWSHelper.h"
#import "Setting.h"
#import "HelpObject.h"
#import "YXDateHelpObject.h"
//#import "NetWorkRequest.h"
////////////////////////////////////////////////////////////////////////
const NSString* PWSCalendarDayCellId = @"PWSCalendarDayCellId";
////////////////////////////////////////////////////////////////////////
@interface PWSCalendarDayCell()
{
    UILabel* m_date;
}

@property (nonatomic,copy) NSDate * dateS;

//  创建原点
@property (nonatomic, strong) UIView * myView;

@end
////////////////////////////////////////////////////////////////////////
@implementation PWSCalendarDayCell

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
//    for (UIView * view in self.contentView.subviews) {
//        if ([view isKindOfClass:[UILabel class]]) {
//            [view removeFromSuperview];
//        }
//    }
//    [self.contentView.subviews performSelector:@selector(removeFromSuperview)];
    
    if (self)
    {
        [self SetInitialValue];
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}

//- (void)awakeFromNib {
//
//}

- (void) SetInitialValue
{
    m_date = [[UILabel alloc] init];
    [m_date setFrame:CGRectMake(Width / 14 - 42 / 2.0 , 0, 42, 42)];
    [m_date setText:@""];
    [m_date setTextAlignment:NSTextAlignmentCenter];
    [self addSubview:m_date];
    // 当有数据时 创建下面那个圆点
    _myView = [[UIView alloc] initWithFrame:CGRectMake(Width / 14 - 1.5, 33, 3, 3)];
    //_myView = [[UIView alloc] initWithFrame:CGRectMake(Width / 14 - 1.5, 47, 5, 5)];
    [self addSubview:_myView];
    _myView.clipsToBounds = YES;
    _myView.layer.cornerRadius = 1.5;
    _myView.backgroundColor = [UIColor grayColor];
    
}

- (void) SetDate:(NSDate*)_date
{
    NSString* day = @"";
    if (_date)
    {
        NSDateComponents *dateComponents = [[NSCalendar currentCalendar] components:NSCalendarUnitDay|NSCalendarUnitMonth fromDate:_date];
        day = [NSString stringWithFormat:@"%@", @(dateComponents.day)];
        //传过来的数组时间
        NSString * curentDate = [[YXDateHelpObject manager] getCurentTime:@"yyyy/MM/dd" dateN:_date];
        NSInteger i = 0;
        
        //便利数组是不是时间相等
        for (NSString * strDate in self.dataArray) {
            //数组中的date和传过来的数据是相等的这个时候直接就添加一个view
            if ([strDate isEqualToString:curentDate]) {
                i = 1;
            }
        }
        
        //时间不等
        if (i == 0) {
            //隐藏点
            _myView.hidden = YES;
        } else {
            //不隐藏点
            _myView.hidden = NO;
        }

    } else {
        //  没有数据时候直接删掉View
        _myView.hidden = YES;
        
    }
    
    m_date.clipsToBounds = YES;
    m_date.layer.cornerRadius = 42 / 2.0;
    // 设置今天 没有点击今天那么直接外边加个圈 点击时直接变为圆
    if ([PWSHelper CheckSameDay:_date AnotherDate:[NSDate date]]) {
        
        [m_date setTextColor:[UIColor grayColor]];
        m_date.layer.borderColor = [UIColor colorWithRed:66/256.0 green:162/256.0 blue:255/256.0 alpha:1.0].CGColor;
        m_date.layer.borderWidth = 1.5;
        //m_date.layer.borderWidth = 2;
        
        //  不是今天的不进行clip
    } else  {
        m_date.layer.borderWidth = 0;
    }
    
    //设置字体的以及其他的颜色等等
    if ([PWSHelper CheckSameDay:_date AnotherDate:_pswSelectDate]) {
        
        m_date.backgroundColor = [UIColor colorWithRed:66/256.0 green:162/256.0 blue:255/256.0 alpha:1.0];
        [m_date setTextColor:[UIColor whiteColor]];
        _myView.backgroundColor = [UIColor redColor];
        
        //否则不用设置颜色等等
    } else {
        
        m_date.backgroundColor = [UIColor clearColor];
        [m_date setTextColor:[UIColor blackColor]];
        _myView.backgroundColor = [UIColor redColor];
        
    }
        [m_date setText:day];

}


@end
